/**
 * @param {string} s 字符串有-，重新加密序列
 * @param {number} k 每段的长度
 * @return {string}
 */
var licenseKeyFormatting = function (s, k) {
    let result = [[]];
    let newstr = s.split("-").join("").split("");
    let first = newstr.length % k;
    for (let i = 0; i < first; i++) {
        result[0].push(newstr[i].toUpperCase())
    }
    newstr = newstr.slice(first, newstr.length);
    let tag = 1;
    result[1] = []
    for (let i = 0; i < newstr.length; i++) {
        if (i != 0 && i % (k) == 0) {
            tag++;
            result[tag] = [];
        }
        result[tag].push(newstr[i].toUpperCase());
    }
    let laststr = []
    for (item of result) {
        if (item.length != 0) {
            laststr.push(item.join(""));
        }
    }
    return laststr.join("-");
};
console.log(licenseKeyFormatting("2-4A0r7-4k", 3))